<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>访客管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd/X-admin/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd/X-admin/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd/X-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/3rd/X-admin/js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>用户登录帐号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="account" name="account" required="" lay-verify="required" value="${user.account}" readonly="readonly"
                           style="    background-color: #eee;"
                           autocomplete="off" class="layui-input">
                </div>
            </div> <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>用户名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required" value="${user.name}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="age" class="layui-form-label">
                    用户年龄
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="age" name="age" required=""  value="${user.age}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="age" class="layui-form-label">
                    <span class="x-red">*</span>手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" required="" lay-verify="required" value="${user.phone}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="age" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="password" name="password" required="" value="${user.password}" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="age" class="layui-form-label">
                    mac地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="mac" name="mac" value="${user.mac}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="age" class="layui-form-label">
                    备注
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="remark" name="remark" value="${user.remark}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>可设置头像</legend>
            </fieldset>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <c:if test="${empty user.headPic}">
                        <img class="layui-upload-img" id="demo1" style="width: 66%; padding-left: 20%;">
                    </c:if>
                    <c:if test="${not empty user.headPic}">
                        <img class="layui-upload-img" id="demo1" style="width: 66%; padding-left: 20%;" src="${user.headPic}">
                    </c:if>
                    <input type="hidden" id="headPic" name="headPic"  value="${user.headPic}"  >
                </div>
            </div>
            <div class="layui-form-item">
                <input  value="${user.id}" id="id" type="hidden"/>
                <button type="button" class="layui-btn" id="uploadImg" style="margin-left: 100px;">上传图片</button>
                <button  class="layui-btn" lay-filter="add" lay-submit="" style="    margin-left: 40px;">
                    保存更改
                </button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer','upload'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            upload= layui.upload,
            layer = layui.layer;
        form.on('submit(add)',
            function(data) {
                var datas={name:$("#name").val(),age:$("#age").val(),phone:$("#phone").val()
                    ,password:$("#password").val()  ,mac:$("#mac").val(),account:$("#account").val(),headPic:$("#headPic").val()
                    ,id:$("#id").val() ,remark:$("#remark").val()
                };
                $.post("${pageContext.request.contextPath}/userManager/updateUser", datas, function (data) {
                    var result=eval(data);
                    if (result.status==300) {
                        layer.alert("修改失败，帐号已经存在", {icon: 5});
                    }else if (result.status==200) {
                        layer.alert("修改成功", {icon: 6 },
                            function() {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                top.location.reload();
                            });
                    } else {
                        layer.alert("修改失败", {
                                icon: 5
                            },
                            function() {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                    }
                });
                return false;
            });

        var uploadInst = upload.render({
            elem: '#uploadImg'
            ,url: '${pageContext.request.contextPath}/uploadImg'
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result);
                    $('#headPic').val(result);
                });
            }
            ,done: function(res){
            }
            ,error: function(){
            }
        });

    });
</script>
</body>

</html>
